package org.dizem.groupon.service.impl;

import org.apache.log4j.Logger;
import org.dizem.groupon.dao.ItemDAO;
import org.dizem.groupon.dao.ReplyDAO;
import org.dizem.groupon.dao.UserDAO;
import org.dizem.groupon.model.domain.ReplyEntity;
import org.dizem.groupon.service.ReplyService;

import java.util.Date;
import java.util.List;

/**
 * User: dizem
 * Time: 11-7-20 下午7:16
 */
public class ReplyServiceImpl implements ReplyService {
	private Logger log = Logger.getLogger(ReplyServiceImpl.class);

	private ReplyDAO replyDAO;
	private UserDAO userDAO;
	private ItemDAO itemDAO;

	public ItemDAO getItemDAO() {
		return itemDAO;
	}

	public void setItemDAO(ItemDAO itemDAO) {
		this.itemDAO = itemDAO;
	}

	public UserDAO getUserDAO() {
		return userDAO;
	}

	public void setUserDAO(UserDAO userDAO) {
		this.userDAO = userDAO;
	}

	public ReplyDAO getReplyDAO() {
		return replyDAO;
	}

	public void setReplyDAO(ReplyDAO replyDAO) {
		this.replyDAO = replyDAO;
	}

	public void save(ReplyEntity object) {
		replyDAO.save(object);
	}

	public void delete(ReplyEntity object) {
		replyDAO.delete(object);
	}

	public void update(ReplyEntity object) {
		replyDAO.update(object);
	}

	public ReplyEntity getById(int id) {
		return replyDAO.getById(id);
	}

	public List<ReplyEntity> loadAll() {
		return replyDAO.loadAll();
	}

	public List<ReplyEntity> load(int firstResult, int maxResult) {
		return replyDAO.load(firstResult, maxResult);
	}

	public int getCount() {
		return replyDAO.getCount();
	}

	public List<ReplyEntity> getByItemId(int id) {
		return replyDAO.getByItemId(id);
	}

	public void save(ReplyEntity reply, String username, int itemId) {
		reply.setUser(userDAO.getByUsername(username));
		reply.setItemId(itemId);
		reply.setTime(new Date());
		log.info("save reply " + reply);
		save(reply);
	}
}
